home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / settaskpri.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  2KB  |  111 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: settaskpri.c,v 1.5 1996/10/24 15:50:58 aros Exp $
  4.     $Log: settaskpri.c,v $
  5.     Revision 1.5  1996/10/24 15:50:58  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/08/13 13:56:08  digulla
  9.     Replaced AROS_LA by AROS_LHA
  10.     Replaced some AROS_LH*I by AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:20  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang: english
  18. */
  19. #include <exec/execbase.h>
  20. #include <aros/libcall.h>
  21.  
  22. /*****************************************************************************
  23.  
  24.     NAME */
  25.     #include <clib/exec_protos.h>
  26.  
  27.     AROS_LH2(BYTE, SetTaskPri,
  28.  
  29. /*  SYNOPSIS */
  30.     AROS_LHA(struct Task *, task,      A1),
  31.     AROS_LHA(LONG,          priority,  D0),
  32.  
  33. /*  LOCATION */
  34.     struct ExecBase *, SysBase, 50, Exec)
  35.  
  36. /*  FUNCTION
  37.     Change the priority of a given task. As a general rule the higher
  38.     the priority the more CPU time a task gets. Useful values are within
  39.     -127 to 5.
  40.  
  41.     INPUTS
  42.     task     - Pointer to task structure.
  43.     priority - New priority of the task.
  44.  
  45.     RESULT
  46.     Old task priority.
  47.  
  48.     NOTES
  49.  
  50.     EXAMPLE
  51.  
  52.     BUGS
  53.  
  54.     SEE ALSO
  55.  
  56.     INTERNALS
  57.  
  58.     HISTORY
  59.  
  60. ******************************************************************************/
  61. {
  62.     AROS_LIBFUNC_INIT
  63.  
  64.     BYTE old;
  65.  
  66.     /* Always Disable() when doing something with task lists. */
  67.     Disable();
  68.  
  69.     /* Get returncode */
  70.     old=task->tc_Node.ln_Pri;
  71.  
  72.     /* Set new value. */
  73.     task->tc_Node.ln_Pri=priority;
  74.  
  75.     /* Check if the task is willing to run. */
  76.     if(task->tc_State!=TS_WAIT)
  77.     {
  78.     /* If it is in the ready list remove and reinsert it. */
  79.     if(task->tc_State==TS_READY)
  80.     {
  81.         Remove(&task->tc_Node);
  82.         Enqueue(&SysBase->TaskReady,&task->tc_Node);
  83.     }
  84.  
  85.     /*
  86.         I could check the task priorities here to determine if
  87.         the following is really necessary, but OTOH priority
  88.         changes are rare and the hassle isn't really worth it.
  89.     */
  90.  
  91.     /* Are taskswitches allowed? */
  92.     if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  93.         /* No. Store it for later. */
  94.         SysBase->AttnResched|=0x80;
  95.     else
  96.     {
  97.         /* Switches are allowed. Move the current task away. */
  98.         SysBase->ThisTask->tc_State=TS_READY;
  99.         Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  100.  
  101.         /* And force a rescedule. */
  102.         Switch();
  103.     }
  104.     }
  105.  
  106.     /* All done. */
  107.     Enable();
  108.     return old;
  109.     AROS_LIBFUNC_EXIT
  110. } /* SetTaskPri */
  111.